package compiler;

import br.ufpe.abaco.ParserGen.parser.SemanticAction;
import java.lang.reflect.*;

class ExecuteConstructor implements SemanticAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	Constructor<?> ct;
	ExecuteConstructor(Constructor<?> c) {
		ct = c;
	}
	Object[] removeNULL(Object[] o) {
		int countNull = 0;
		for (int c=0;c<o.length;c++)
			if (o[c]==null)
				countNull++;
		if (countNull==0) return o;
		Object result[] = new Object[o.length-countNull];
		int c2=0;
		for (int c=0;c<o.length;c++)
			if (o[c]!=null)
				result[c2++] = o[c];
		return result;
				
	}
	public Object act(Object[] values)  {
		// TODO Auto-generated method stub
		try {
			return ct.newInstance(removeNULL(values));
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
	}
	
}
